import 'package:changxindianzishangwu/dao/collect_dao.dart';
import 'package:changxindianzishangwu/model/collect_list_model.dart';
import 'package:changxindianzishangwu/pages/my/collect_fragment_page.dart';
import 'package:changxindianzishangwu/pages/my/collect_page.dart';
import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:changxindianzishangwu/widget/app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class CollectSearchPage extends StatefulWidget {
  const CollectSearchPage({Key key}) : super(key: key);

  @override
  _CollectSearchPageState createState() => _CollectSearchPageState();
}

class _CollectSearchPageState extends State<CollectSearchPage> {
  TextEditingController _controller;
  CollectFragmentPage _controllerFragment = CollectFragmentPage(
    isSearch: true,
  );

  @override
  void initState() {
    _controller = TextEditingController();
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    EasyLoading.dismiss();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TopAppBar(
        context,
        "搜索",
        rightText: "完成",
        isRightTextBtn: true,
        rightCallback: () {
          setState(() {
            FocusScope.of(context).requestFocus(FocusNode());
            _controllerFragment.searchData(_controller.text.toString());
          });
        },
      ),
      resizeToAvoidBottomInset: false,
      body: CustomScrollView(slivers: [
        SliverToBoxAdapter(
          child: Container(
            margin: EdgeInsets.only(
                left: width(15), right: width(15), bottom: height(15)),
            child: TextField(
              maxLength: 10,
              controller: _controller,
              maxLines: 1,
              keyboardType: TextInputType.text,
              style: TextStyle(color: AppColor.colorText85, fontSize: 15),
              decoration: InputDecoration(
                  fillColor: AppColor.bg,
                  filled: true,
                  counterText: "",
                  contentPadding: EdgeInsets.only(left: 15, right: 15),
                  hintText: "请输入搜索内容...",
                  hintStyle:
                      TextStyle(color: AppColor.colorHintText, fontSize: 15),
                  enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Color(0x00FF0000)),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(color: Color(0x00000000)),
                      borderRadius: BorderRadius.all(Radius.circular(5)))),
              onEditingComplete: () {
                setState(() {
                  FocusScope.of(context).requestFocus(FocusNode());
                  _controllerFragment.searchData(_controller.text.toString());
                });
              },
              textInputAction: TextInputAction.done,
            ),
          ),
        ),
        SliverFillRemaining(
          fillOverscroll: true,
          child: _controllerFragment,
        ),
      ]),
    );
  }
}
